package com.wxgo.controller.admin;

import java.util.List;

import com.jfinal.core.Controller;
import com.wxgo.common.model.Module;
import com.wxgo.factory.DaoFactory;

public class ModuleController extends Controller {

	public void manage() {
		Integer pmid = getParaToInt("pmid", 0);
		setAttr("pmid", pmid);
		List<Module> moduleList = DaoFactory.moduleDao().findModuleByParentId(pmid);
		setAttr("tableList", moduleList);
		render("/admin/module/moduleManage.html");
	}

	public void add() {
		Integer pmid = getParaToInt("pmid", 0);
		setAttr("pmid", pmid);
		List<Module> moduleList = DaoFactory.moduleDao().findModuleByParentId(0);
		setAttr("moduleList", moduleList);
		render("/admin/module/moduleAdd.html");
	}

	public void save() {
		Module module = getModel(Module.class, "module");
		module.save();
		manage();
		return;
	}

	public void delete() {
		String id = getPara("id");
		DaoFactory.moduleDao().delete("module", id);
		manage();
	}

	public void edit() {
		Integer id = getParaToInt("id");
		Module module = DaoFactory.moduleDao().findById(id);
		setAttr("module", module);
		List<Module> moduleList = DaoFactory.moduleDao().findModuleByParentId(0);
		setAttr("moduleList", moduleList);
		render("/admin/module/moduleEdit.html");
	}

	public void update() {
		Module module = getModel(Module.class, "module");
		module.update();
		manage();
		return;
	}

	public void open() {
		Integer pmid = getParaToInt("id");
		List<Module> moduleList = DaoFactory.moduleDao().findModuleByParentId(pmid);
		setAttr("moduleList", moduleList);
		render("/child/index.html");
	}
}
